var form = layui.form;

layui.use('laydate', function(){
    var laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem: '#birthday' //指定元素
    });
    laydate.render({
        elem: '#graduationDay' //指定元素
    });
});

//意向城市下拉框
var cityOption = {
    el: '#intendedCity',
    name: 'intendedCity',//表单的name属性
    id: 'intendedCity',
    initValue: ['东莞'],//默认项
    layVerify: 'required',//必填项
    //layVerType: 'tips',//提示类型 同layui
    tips: '请选择意向城市...',
    data: [{name: '东莞',value: '东莞'},
        {name: '深圳',value: '深圳'},
        {name: '上海',value: '上海'},
        {name: '杭州',value: '杭州'}],
};
var city = xmSelect.render(cityOption)

//英语水平下拉框
var englishLevelOption = {
    el: '#englishLevel',
    name: 'englishLevel',//表单的name属性
    id: 'englishLevel',
    layVerify: 'required',//必填项
    //layVerType: 'tips',//提示类型 同layui
    tips: '请选择英语水平...',
    data: [{name: '可用书面形式沟通',value: '可用书面形式沟通'},
        {name: '可用口语形式沟通',value: '可用口语形式沟通'},
        {name: '一般',value: '一般'},
        {name: '不擅长',value: '不擅长'}],
};
var englishLevel = xmSelect.render(englishLevelOption)

//英语证书下拉框
var englishCertificateOption = {
    el: '#englishCertificate',
    name: 'englishCertificate',//表单的name属性
    id: 'englishCertificate',
    layVerify: 'required',//必填项
    //layVerType: 'tips',//提示类型 同layui
    tips: '请选择英语证书...',
    data: [
        {name: '四级证书',value: '四级证书'},
        {name: '六级证书',value: '六级证书'},
        {name: '无',value: '无'},
        {name: '其他证书',value: '其他证书'}
    ],
};
var englishCertificate = xmSelect.render(englishCertificateOption)

//办公软件下拉框
var officeSoftwareOption = {
    el: '#officeSoftware',
    name: 'officeSoftware',//表单的name属性
    id: 'officeSoftware',
    layVerify: 'required',//必填项
    //layVerType: 'tips',//提示类型 同layui
    tips: '请选择擅长的办公软件...',
    data: [
        {name: 'Word',value: 'Word'},
        {name: 'Excel',value: 'Excel'},
        {name: 'PPT',value: 'PPT'},
        {name: 'PS',value: 'PS'},
        {name: 'CAD',value: 'CAD'},
        {name: 'UG',value: 'UG'},
        {name: 'H5',value: 'H5'},
        {name: '其他',value: '其他'},
    ],
};
var officeSoftware = xmSelect.render(officeSoftwareOption)

//下一项
$('#nextItem').click(function () {
    //校验填写完整
    if(checkData(form.val('data'))==false){
        layer.alert('您还有信息未填写！<br>请填写完整个人信息', {
            icon: 2,
            skin: 'layer-ext-demo' //见：扩展说明
        })
    }else {
        $.ajax({
            url: '' + '/apply-info/checkFilling',
            method: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({
                applyUserName: $('input[name=applyUserName]').val(),
                telephone: $('input[name=telephone]').val(),
            }),
            async:false,
            success: function(res) {
                if (res.code == 200) {
                    layer.open({
                        type: 1,
                        title: '在线填报',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area: ['100%', '100%'],
                        content: $('#nextBox'),
                        end: function () {
                            $('#nextBox').css('display', 'none')
                        },
                        success:function () {
                            //时间选择器生成
                            for(var i=1;i<=3;i++){
                                //定义3个元素
                                var trainElem="#trainTime"+"_"+i
                                var startElem="#startTime"+"_"+i
                                var endElem="#endTime"+"_"+i
                                layui.use('laydate', function(){
                                    var laydate = layui.laydate;
                                    //执行一个laydate实例
                                    laydate.render({
                                        elem: trainElem //指定元素
                                    });
                                });
                                layui.use('laydate', function(){
                                    var laydate = layui.laydate;
                                    //执行一个laydate实例
                                    laydate.render({
                                        elem: startElem //指定元素
                                    });
                                });
                                layui.use('laydate', function(){
                                    var laydate = layui.laydate;
                                    //执行一个laydate实例
                                    laydate.render({
                                        elem: endElem //指定元素
                                    });
                                });
                            }//生成结束
                        }
                    });
                }else {
                    layer.msg("检测到您已经提交过个人信息！禁止重复提交！")
                }
            }
        });
    }
    return false;
})

//提交按钮
$('#submitBtn').click(function () {
    var data = form.val('data');
    data.thisPolitical=$('input[name="tPolitical"]:checked').val();
    data.trainInfoVos=[];
    data.internshipInfoVos=[];
    data.familyInfoVos=[];
    for (var i = 1; i <= 3; i++) {
        //培训经历
        var trainTime="#trainTime_"+i;
        var trainInfo="input[name='trainInfo_"+i+"']";
        var obtainCertificate="input[name='obtainCertificate_"+i+"']:checked";
        data.trainInfoVos.push({
            trainTime: $(trainTime).val(),
            trainInfo: $(trainInfo).val(),
            obtainCertificate :$(obtainCertificate).val()
        })
        //实习经历
        var startTime="#startTime_"+i;
        var endTime="input[name='endTime_"+i+"']";
        var companyName="input[name='companyName_"+i+"']";
        var postName="input[name='postName_"+i+"']";
        data.internshipInfoVos.push({
            startTime: $(startTime).val(),
            endTime: $(endTime).val(),
            companyName :$(companyName).val(),
            postName :$(postName).val()
        })
        //家庭成员
        var appellation="input[name='appellation_"+i+"']";
        var name="input[name='name_"+i+"']";
        var nowLive="input[name='nowLive_"+i+"']";
        var nowWorkplace="input[name='nowWorkplace_"+i+"']";
        data.familyInfoVos.push({
            appellation: $(appellation).val(),
            name: $(name).val(),
            nowLive :$(nowLive).val(),
            nowWorkplace :$(nowWorkplace).val(),
        })
    }
    console.log(data)
    //提交
    $.ajax({
        url: '' + '/apply-info/addApplyInfo',
        method: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(data),
        async:false,
        success: function(res) {
            parent.layer.msg(res.msg);
            if (res.code == 200) {
                location.reload();
            }
        }
    });
})